$li = $('nav>ul>li')
$li.mouseenter(function () {
    $(this).children('ul').stop().slideDown()
    $(this).parent().parent().next('div').stop().slideDown()
    $(this).children('a').removeClass('col_a')
})
$li.mouseleave(function () {
    $(this).children('ul').stop().slideUp()
    $(this).parent().parent().next('div').stop().slideUp()
    $(this).children('a').addClass('col_a')
})

//轮播图
var mySwiper = new Swiper('.swiper-container', {
    loop: true,
    autoplay: true,
    pagination: {
        el: '.swiper-pagination',
        bulletElement: 'li',
        clickable: true,
    },
});
mySwiper.el.onmouseover = function () {
    mySwiper.autoplay.stop();
}
mySwiper.el.onmouseout = function () {
    mySwiper.autoplay.start();
}

var left = document.querySelector('.left')
var idArr = location.search.match(/id=(\d+)/)
var tokenArr = location.search.match(/token=([^&]+)/)
if (idArr && tokenArr) {
    var id = idArr[1]
    var token = tokenArr[1]
    document.querySelector('.list').setAttribute('href', "list.html?token=" + token + '&id=' + id)
    var xhr = new XMLHttpRequest
    xhr.open('get', `http://localhost:8888/users/info/${id}`)
    xhr.setRequestHeader('authorization', token)
    xhr.send()
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status >= 200 && xhr.status < 300) {
                var res = xhr.responseText
                res = JSON.parse(res)
                var { code, info: { username } } = res
                left.innerHTML = `
                    <span class="effort">每一个不曾起舞的日子，都是对生命的辜负</span>
                    <a data-id="${id}" data-token="${token}" href="javascript:;" class="logout">退出</a>
                `
            }
        }
    }
}
left.onclick = function () {
    var target = window.event.target || window.event.srcElement
    if (target.className = 'logout') {
        var xhr = new XMLHttpRequest
        xhr.open('get', 'http://localhost:8888/users/logout/' + target.getAttribute('data-id'))
        xhr.setRequestHeader('authorization', target.getAttribute('token'))
        xhr.send()
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                var res = xhr.responseText
                res = JSON.parse(res)
                console.log(res)
                var { code, message } = res
                if (code === 1) {
                    alert(message)
                    location.href="home.html"
                }
            }
        }
    }
}